package com.cms.meeting.controller;

import com.cms.meeting.entity.Department;
import com.cms.meeting.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Controller
@RequestMapping("/admin")
public class DepartmentController {
    @Autowired
    DepartmentService departmentService;

    @RequestMapping ("/departments")
    public String Department(Model model){
        model.addAttribute("deps",departmentService.getAllDeps());
        return "departments";
    }
    @RequestMapping("/adddepartment")
    public String AddDepartment(String departmentname){
        departmentService.adddepartment(departmentname);
        return "redirect:/admin/departments";
    }
    @RequestMapping("/deletedep")
    public String deleteDep(Integer departmentid){
        departmentService.deleteDep(departmentid);
        return "redirect:/admin/departments";
    }
    @RequestMapping("/updatedep")
    @ResponseBody
    public String updatedep(String name,Integer id){
       Integer result = departmentService.updatedep(id , name);
       if (result == 1){
return "success";
       }
        return "error";
    }

}
